package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.mapper.OpenPeriodMapper;
import com.rongke.model.OpenPeriod;
import com.rongke.service.OpenPeriodService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * @OpenPeriodController
 * @访客时段分布Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/openPeriod")
@Transactional
@CrossOrigin
public class OpenPeriodController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private OpenPeriodService openPeriodService;

    /**
     * @添加访客时段分布
     * @param openPeriod
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addOpenPeriod(@RequestBody OpenPeriod openPeriod){
        log.debug("添加访客时段分布");
        openPeriodService.insert(openPeriod);
        return JsonResp.ok(openPeriod);
    }

    /**
     * @修改访客时段分布
     * @param openPeriod
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateOpenPeriod(@RequestBody OpenPeriod openPeriod){
        log.debug("修改访客时段分布");
        openPeriodService.updateById(openPeriod);
        return JsonResp.ok(openPeriod);
    }
    /**
     * @根据id查找访客时段分布
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectOpenPeriod(Long id){
        log.debug("查找访客时段分布");
        OpenPeriod openPeriod = openPeriodService.selectById(id);
        return JsonResp.ok(openPeriod);
    }

    /**
     * @根据条件查找访客时段分布
     * @param openPeriod
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectOpenPeriodByCondition(@RequestBody OpenPeriod openPeriod){
        log.debug("根据条件查找访客时段分布");
        if(openPeriod==null)
            return JsonResp.toFail("参数不能为空");
        List<OpenPeriod> openPeriodList=openPeriodService.selectByCondition(openPeriod);
        return JsonResp.ok(openPeriodList);
    }

}
